import { ElMessage, ElMessageBox } from 'element-plus'

const openMessageBox = (title,validator,icon,successMsg,errorMsg) => {
  return new Promise((resolve,reject)=>{
    ElMessageBox.prompt(title, 'Tip', {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      draggable:true,
      autofocus:true,
      inputValidator:validator,
      icon ,
    }).then(({ value }) => {
      ElMessage({
        type: 'success',
        message: successMsg,
      })
      resolve(value)
    })
      .catch((error) => {
        ElMessage({
          type: 'info',
          message: errorMsg,
        })
        reject(error)
      })
  })

}

export {
  openMessageBox
}
